package com.cms.entity;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.cms.entity.base.BaseModel;
import com.cms.util.DBUtils;
import com.jfinal.plugin.activerecord.Page;

/**
 * Entity - 模型
 * 
 * 
 * 
 */
@SuppressWarnings("serial")
public class Model extends BaseModel<Model> {
    
    //栏目
    public static int CATEGORY_TYPE=1;
    //表单
    public static int FORM_TYPE=2;
    //数据库表
    public static int TABLE_TYPE=3;
    
	
	/**
	 * 查找模型分页
	 * 
	 * @param pageNumber
	 *            页码
	 * @param pageSize
	 *            每页记录数
	 * @return 模型分页
	 */
	public Page<Model> findPage(String name,Integer pageNumber,Integer pageSize,Long siteId){
	    String filterSql = " and siteId="+siteId;
        if(StringUtils.isNotBlank(name)){
            filterSql+= " and name like '%"+name+"%'";
        }
	    String orderBySql = DBUtils.getOrderBySql("createDate desc");
		return paginate(pageNumber, pageSize, "select *", "from cms_model where 1=1 "+filterSql+orderBySql);
	}
	
	/**
	 * 查找模型
	 * 
	 * @return 查找模型
	 */
	public List<Model> findList(Integer type,Long siteId){
	    String filterSql = " and siteId="+siteId;
        if(type!=null){
            filterSql+= " and type="+type;
        }
		return find("select * from cms_model where 1=1 "+filterSql);
	}
}
